package com.agileboot.medicine.controller.algorithm;

import java.util.HashSet;
import java.util.Set;

/**
 * 草药用途相似度计算（Jaccard 相似度）
 */
public class HerbUsesSimilarityCalculator {

    public static double calculateJaccardSimilarity(Set<String> uses1, Set<String> uses2) {
        Set<String> intersection = new HashSet<>(uses1);
        intersection.retainAll(uses2);

        Set<String> union = new HashSet<>(uses1);
        union.addAll(uses2);

        return (double) intersection.size() / union.size();
    }
}
